package com.startertest.autocinfguration;

import com.startertest.bean.MyBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shenjies88
 * @since 2023/1/27/19:33
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(value = {MyBeanProperty.class, MyBean.class})
@EnableConfigurationProperties(MyBeanProperty.class)
public class MyAutoConfiguration {

    @ConditionalOnMissingBean
    @Bean
    public MyBean myBean(MyBeanProperty myBeanProperty) {
        MyBean myBean = new MyBean();
        myBean.setName(myBeanProperty.getName());
        myBean.setAge(myBeanProperty.getAge());
        return myBean;
    }
}
